#!/bin/bash
BASHDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
RateTrainingFile="$BASHDIR/RateTraining.txt"
RateValingFile="$BASHDIR/RateValing.txt"
DataDir="/home/cgf/DataCollection/data"
cd $DataDir
if [ -f $RateTrainingFile ]
then
	echo "remove $RateTrainingFile"
	rm $RateTrainingFile
fi
if [ -f $RateValingFile ]
then
	echo "remove $RateValingFile"
	rm $RateValingFile
fi
rate=0.7
for dir in `find . -type d ! -name "."`
do
	filecount=`ls $dir | wc -l`
	trainfilecount=`echo $filecount*$rate/1 | bc`
	valfilecount=`echo $filecount-$trainfilecount | bc`
	echo "dir=$dir"
	echo "filecount=$filecount"
	echo "trainfilecount=$trainfilecount"
	echo "valfilecount=$valfilecount"
	trainlist=`shuf -i 1-$filecount -n $trainfilecount`
	#echo $trainlist >> "$BASHDIR/log.txt"
	index=0
	for file in `find $dir -maxdepth 1 -name "*.jpg"`
	do
		index=`echo $index+1 | bc`
		#echo "index=$index" >> "log.txt"
		if [[ $trainlist =~ $index ]]
		then
			#echo "train"
			echo $file >> $RateTrainingFile
		else
			#echo "val"
			echo $file >> $RateValingFile
		fi
		#echo $file
	done
done
echo 'done'
